package com.aierkeji.call.b2c.util;

import java.io.UnsupportedEncodingException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;


public class AppConfig {
	private static final Logger log = LoggerFactory.getLogger(AppConfig.class);

	private static  Environment properties;

	public static void builder(Environment properties) {
		AppConfig.properties = properties;
		
	}
	
	
	


	public static String getProperty(String key) {
		return getProperty(key, null);
	}

	public static String getProperty(String key, String defaultValue) {
		try {
			return properties.getProperty(key, defaultValue);
		} catch (Exception e) {
			e.printStackTrace();
			return defaultValue;
		}
	}

	public static String getPropertyEncoding(String key, String encoding) {
		return getPropertyEncoding(key, encoding, null);
	}

	public static String getPropertyEncoding(String key, String encoding, String defaultValue) {
		String str = getProperty(key, defaultValue);
		try {
			// 进行编码转换，解决问题
			str = new String(str.getBytes("ISO8859-1"), encoding);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			log.error(e.getMessage(), e);
		}
		return str;
	}

}